package work.mediway.bi.model.vo;

import cn.hutool.core.collection.CollUtil;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.parser.Feature;
import work.mediway.bi.model.entity.DatasetConfig;
import lombok.Data;

import java.util.Date;
import java.util.List;

/**
 * @author bovane <bovane.ch@gmail.com>
 * @description
 * @create 2023-07-10 10:12
 */
@Data
public class DataSetConfigVO {
    /**
     * 数据集ID
     */
    private String apiId;

    /**
     * 数据集名称
     */
    private String apiName;

    /**
     * 数据集描述
     */
    private String apiDesc;

    /**
     * 创建人
     */
    private String createBy;

    /**
     * 创建时间
     */
    private Date createTime;

    /**
     * 更新人
     */
    private String updateBy;

    /**
     * 更新时间
     */
    private Date updateTime;

    /**
     * 数据集配置
     */
    private JSON apiCfg;

    /**
     * 是否启用
     */
    private Boolean actived;

    public static List<DataSetConfigVO> convert(List<DatasetConfig> datasetConfigs) {
        List<DataSetConfigVO> dataSetConfigVOS = CollUtil.newArrayList();
        for (DatasetConfig datasetConfig:datasetConfigs) {
            DataSetConfigVO dataSetConfigVO = new DataSetConfigVO();
            dataSetConfigVO.setApiId(datasetConfig.getApiId());
            dataSetConfigVO.setApiName(datasetConfig.getApiName());
            dataSetConfigVO.setApiDesc(datasetConfig.getApiDesc());
            dataSetConfigVO.setActived(datasetConfig.getActived());
            dataSetConfigVO.setCreateBy(datasetConfig.getCreateBy());
            dataSetConfigVO.setCreateTime(datasetConfig.getCreateTime());
            dataSetConfigVO.setUpdateBy(datasetConfig.getUpdateBy());
            dataSetConfigVO.setUpdateTime(datasetConfig.getUpdateTime());
            JSON json = JSON.parseObject(datasetConfig.getApiCfg(), Feature.OrderedField);
            dataSetConfigVO.setApiCfg(json);
            dataSetConfigVOS.add(dataSetConfigVO);
        }
        return dataSetConfigVOS;
    }
}
